<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: DoubleBuffer/DoubleBuffer.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 VGA Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_double_buffer_2_double_buffer_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">DoubleBuffer/DoubleBuffer.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>Show double buffering usage</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - www.fabgl.com</span></div><div class="line"><span class="comment">  Copyright (c) 2019 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  This file is part of FabGL Library.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#define DOUBLEBUFFERING 1</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>Test {</div><div class="line">  <span class="keyword">virtual</span> ~Test() { };</div><div class="line">  <span class="keyword">virtual</span> <span class="keywordtype">void</span> update() = 0;</div><div class="line">  <span class="keyword">virtual</span> <span class="keywordtype">bool</span> nextState() = 0;</div><div class="line">  <span class="keyword">virtual</span> <span class="keywordtype">int</span> testState() = 0;</div><div class="line">  <span class="keyword">virtual</span> <span class="keywordtype">char</span> <span class="keyword">const</span> * name() = 0;</div><div class="line">};</div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;ballstest.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;polygonstest.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;spritestest.h&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line">  VGAController.<a name="a0"></a><a class="code" href="classfabgl_1_1_v_g_a_controller_class.html#acdc8b95372c01a76deeb4abe360d0295">begin</a>();</div><div class="line">  VGAController.<a name="a1"></a><a class="code" href="classfabgl_1_1_v_g_a_controller_class.html#ac190a844ead4bb68817c733fb0c9a5af">setResolution</a>(<a name="a2"></a><a class="code" href="fabglconf_8h.html#a053cde6629b66d4ba3e31e92af8861bb">VGA_320x200_75Hz</a>, -1, -1, DOUBLEBUFFERING);</div><div class="line">  <span class="comment">//VGAController.moveScreen(20, 0);</span></div><div class="line">  <span class="comment">//VGAController.moveScreen(-8, 0);</span></div><div class="line"></div><div class="line">  Canvas.<a name="a3"></a><a class="code" href="classfabgl_1_1_canvas_class.html#aec16bab7318419fde24db0b9a78d3281">selectFont</a>(Canvas.<a name="a4"></a><a class="code" href="classfabgl_1_1_canvas_class.html#aae47e5f03e69ed21dd07f4b73e43e4f0">getPresetFontInfo</a>(40, 14)); <span class="comment">// get a font for about 40x14 text screen</span></div><div class="line">  Canvas.<a name="a5"></a><a class="code" href="classfabgl_1_1_canvas_class.html#a4e8cfc8e0e279de0defc88d8e01443dc">setGlyphOptions</a>(GlyphOptions().FillBackground(<span class="keyword">true</span>));</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line">  <span class="keyword">static</span> int64_t stime  = esp_timer_get_time();</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">int</span> FPS        = 0;</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">int</span> FPSCounter = 0;</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">int</span> testIndex  = 0;</div><div class="line">  <span class="keyword">static</span> Test * test    = <span class="keyword">new</span> BallsTest;</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (test-&gt;nextState() == <span class="keyword">false</span>) {</div><div class="line">    <span class="keyword">delete</span> test;</div><div class="line">    ++testIndex;</div><div class="line">    <span class="keywordflow">switch</span> (testIndex) {</div><div class="line">      <span class="keywordflow">case</span> 1:</div><div class="line">        test = <span class="keyword">new</span> PolygonsTest;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> 2:</div><div class="line">        test = <span class="keyword">new</span> SpritesTest;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">default</span>:</div><div class="line">        testIndex = 0;</div><div class="line">        test = <span class="keyword">new</span> BallsTest;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (esp_timer_get_time() - stime &gt; 1000000) {</div><div class="line">    <span class="comment">// calculate FPS</span></div><div class="line">    FPS = FPSCounter;</div><div class="line">    stime = esp_timer_get_time();</div><div class="line">    FPSCounter = 0;</div><div class="line">  }</div><div class="line">  ++FPSCounter;</div><div class="line"></div><div class="line">  test-&gt;update();</div><div class="line"></div><div class="line">  <span class="comment">// display test state and FPS</span></div><div class="line">  Canvas.<a name="a6"></a><a class="code" href="classfabgl_1_1_canvas_class.html#a8dbddce234790b290cb4bd053dc0e701">setPenColor</a>(<a name="a7"></a><a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3bab269b90a1d510bf6861b4584f7aa9720">Color::Blue</a>);</div><div class="line">  Canvas.<a name="a8"></a><a class="code" href="classfabgl_1_1_canvas_class.html#a9cec8cd2eb3f498b67ec7f20800131da">setBrushColor</a>(<a name="a9"></a><a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3bacc98be810fb05ecb9fc7ea69a8e251c8">Color::Yellow</a>);</div><div class="line">  Canvas.<a name="a10"></a><a class="code" href="classfabgl_1_1_canvas_class.html#a45b0f278e677b6195ccea7bc377fe8c5">drawTextFmt</a>(80, 5, <span class="stringliteral">&quot; %d %s at %d FPS &quot;</span>, test-&gt;testState(), test-&gt;name(), FPS);</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (DOUBLEBUFFERING)</div><div class="line">    Canvas.<a name="a11"></a><a class="code" href="classfabgl_1_1_canvas_class.html#a548e3986a6701b3794853bf738ef3093">swapBuffers</a>();</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
